package io.renren.modules.seller.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.seller.entity.ProvincesEntity;
import io.renren.modules.seller.service.ProvincesService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 省份信息表
 *
 * @author hou 15373178086@163.com
 * @date 2020-02-16 11:30:48
 */
@RestController
@RequestMapping("seller/provinces")
public class ProvincesController {
    @Autowired
    private ProvincesService provincesService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:provinces:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = provincesService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:provinces:info")
    public R info(@PathVariable("id") Integer id) {
        ProvincesEntity provinces = provincesService.getById(id);

        return R.ok().put("provinces", provinces);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:provinces:save")
    public R save(@RequestBody ProvincesEntity provinces) {
        provincesService.save(provinces);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:provinces:update")
    public R update(@RequestBody ProvincesEntity provinces) {
        ValidatorUtils.validateEntity(provinces);
        provincesService.updateById(provinces);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:provinces:delete")
    public R delete(@RequestBody Integer[] ids) {
        provincesService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
